package yawning.mew.cat;

import yawning.mew.character.Druid.Talent;
import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventBerserk extends SimulationEventAction {
	CatModelSimState mState;
	double mCooldownAt;

	EventBerserk(CatModelSimState state) {
		super(state.mSimUtil);
		mState = state;
		if (mState.mModel.druid.getTalent(Talent.BERSERK) == 0) mCooldownAt = Double.MAX_VALUE;
	}

	@Override
	public double perform() {
		if (isUp() || mCooldownAt > mState.mSimUtil.getSimTime()) return SimulationAction.ACTION_FAIL;
		if (mState.mDebug) mState.DBGF("Berserk");

		mState.nrBerserk++;

		schedule(mState.mModel.berserkBuffDuration);
		mCooldownAt = mState.mSimUtil.getSimTime() + mState.mModel.berserkCDDuration;
		mState.onPrimalMadnessGain();
		return 1.0;
	}

	@Override
	public void onExpire() {
		if (mState.mDebug) mState.DBGF("Berserk Expiration");
		mState.onPrimalMadnessLoss();
	}
}